import { createStore, applyMiddleware, combineReducers } from 'redux'
import { persistStore, persistReducer } from 'redux-persist' // 本地持久化
import storage from 'redux-persist/lib/storage' // 本地持久化方式localstorage
import { composeWithDevTools } from 'redux-devtools-extension'; // 触发redux-devtools工具
import { createLogger } from 'redux-logger'; // redux日志
import createSagaMiddleware from 'redux-saga'
import rootSaga from '../store/saga'

import { storeData } from './reducer'


const logger = createLogger();
const sagaMiddleware = createSagaMiddleware()

const reducers = combineReducers({
    storeData,
})

const persistConfig = {
    key: 'root',
    storage
}
const myPersistReducer = persistReducer(persistConfig, reducers);
const store: any = createStore(
    myPersistReducer,
    composeWithDevTools(applyMiddleware(
        sagaMiddleware,
        logger
    ))
)
sagaMiddleware.run(rootSaga)
const persistor = persistStore(store)
export { store, persistor }
